/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package xdxn.editor.studio;

import java.awt.Toolkit;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import javax.swing.JFrame;
import xdxn.editor.studio.gui.barrage.BarrageMainWindow;

/**
 *
 * @author Cai Han
 */
public class MainFrame extends JFrame {

    /**
     * Creates new form MainFrame
     */
    public MainFrame() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings( "unchecked" )
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        _menubar = new javax.swing.JMenuBar();
        _menu_project = new javax.swing.JMenu();
        _new_project = new javax.swing.JMenuItem();
        _open_project = new javax.swing.JMenuItem();
        _save_project = new javax.swing.JMenuItem();
        _export_project = new javax.swing.JMenuItem();
        _menu_window = new javax.swing.JMenu();
        _menu_barrage_edit_window = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("XdXnStudio");

        _menu_project.setText("项目");

        _new_project.setText("新建项目");
        _menu_project.add(_new_project);

        _open_project.setText("打开项目");
        _menu_project.add(_open_project);

        _save_project.setText("保存项目");
        _menu_project.add(_save_project);

        _export_project.setText("导出项目");
        _menu_project.add(_export_project);

        _menubar.add(_menu_project);

        _menu_window.setText("窗口");

        _menu_barrage_edit_window.setText("弹幕编辑窗口");
        _menu_barrage_edit_window.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                _menu_barrage_edit_windowActionPerformed(evt);
            }
        });
        _menu_window.add(_menu_barrage_edit_window);

        _menubar.add(_menu_window);

        setJMenuBar(_menubar);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 824, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 824, Short.MAX_VALUE)
        );

        pack();
        setLocationRelativeTo(null);
    }// </editor-fold>//GEN-END:initComponents

    /**
     * 开启弹幕编辑器
     */
    private void _menu_barrage_edit_windowActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__menu_barrage_edit_windowActionPerformed
        // TODO add your handling code here:
        BarrageMainWindow b = new BarrageMainWindow("Stringasd");
        // moveFrame2Center_4_5(b);
        this.setEnabled(false);
        b.setVisible(true);
        b.addWindowListener(new MainFrameWinListener(this));
    }//GEN-LAST:event__menu_barrage_edit_windowActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main( String args[] ) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for ( javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels() ) {
                if ( "Windows".equals(info.getName()) ) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch ( ClassNotFoundException | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex ) {
            java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE , null , ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(() -> {
            new MainFrame().setVisible(true);
        });
        
        System.out.println("path : " + System.getProperty("user.dir"));
    }

    class MainFrameWinListener implements WindowListener {

        private MainFrame _mainFrame;

        public MainFrameWinListener( MainFrame mainFrame ) {
            this._mainFrame = mainFrame;
        }

        @Override
        public void windowOpened( WindowEvent e ) {
        }

        @Override
        public void windowClosing( WindowEvent e ) {
            this._mainFrame.setEnabled(true);
        }

        @Override
        public void windowClosed( WindowEvent e ) {
        }

        @Override
        public void windowIconified( WindowEvent e ) {
        }

        @Override
        public void windowDeiconified( WindowEvent e ) {
        }

        @Override
        public void windowActivated( WindowEvent e ) {
        }

        @Override
        public void windowDeactivated( WindowEvent e ) {
        }

    }

    public final void moveFrame2Center_4_5( JFrame jframe ) {
        int screen_width = (int) Toolkit.getDefaultToolkit().getScreenSize().getWidth();
        int screen_height = (int) Toolkit.getDefaultToolkit().getScreenSize().getHeight();
        int frame_width = (screen_width << 2) / 5;
        int frame_height = (screen_height << 2) / 5;
        jframe.setBounds((screen_width - frame_width) / 2 , (screen_height - frame_height) / 2 , frame_width , frame_height);
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuItem _export_project;
    private javax.swing.JMenuItem _menu_barrage_edit_window;
    private javax.swing.JMenu _menu_project;
    private javax.swing.JMenu _menu_window;
    private javax.swing.JMenuBar _menubar;
    private javax.swing.JMenuItem _new_project;
    private javax.swing.JMenuItem _open_project;
    private javax.swing.JMenuItem _save_project;
    // End of variables declaration//GEN-END:variables
}
